
<div class="container-fluid am-cf">
    <div class="row">
        <div class="am-u-sm-12 am-u-md-12 am-u-lg-9">
            <div class="page-header-heading"><span class="am-icon-home page-header-heading-icon"></span> 上传头像</div>
            
        </div>
        <div class="am-u-lg-3 tpl-index-settings-button">
            <button type="button" class="page-header-button"><a href="javascript:history.back(-1)">返回</a></button>
        </div>
    </div>
</div>
<div class="row-content am-cf">
    <div class="row">
        <div class="am-u-sm-12 am-u-md-12 am-u-lg-12">
            <div class="widget am-cf">
                <div class="widget-head am-cf">
                    <div class="widget-title am-fl">上传头像</div>
                    <div class="widget-function am-fr">
                        <a href="javascript:;" class="am-icon-cog"></a>
                    </div>
                </div>
                <div class="widget-body  am-fr">
                    <div class="am-u-sm-12">
                        <form class="am-form tpl-form-line-form">
                            <div class="am-form-group">
                                <label for="user-weibo" class="am-u-sm-3 am-form-label">上传头像：</label>
                                <div class="am-u-sm-9">
                                    <div class="am-form-group am-form-file" style="width: 50%;">
                                        <div class="tpl-form-file-img">
                                            <img class="am-img-thumbnail" id="showImg" src="{$user.avatar}" style="width: 65%;border: none;">
                                        </div>
                                        <input type="hidden" id="order_id" value="">
                                        <div class="am-form-group am-form-file">
                                        
                                        <button type="button" id="test1" class="am-btn am-btn-danger am-btn-sm">
                                            <i class="am-icon-cloud-upload"></i> 上传头像
                                        </button>
                                       
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
</div>
 <script src="__CDN__/assets/less/layui/layui.js"></script>
<script type="text/javascript">
    layui.use('upload', function(){
      var upload = layui.upload;
       
      //执行实例
      var uploadInst = upload.render({
        elem: '#test1', //绑定元素
        size:500
        ,url: '/index/common/upload' //上传接口
        ,done: function(res, index, upload){
          //如果上传失败
          
          if(res.data==''||res.data==null){
              return layer.msg(res.msg);
          }else{
              
               document.getElementById("showImg").src= res.data.url; //图片链接（base64）.src = res.data.url;
               var src=res.data.url
             
               $.post('user/profilesingle',{field:"avatar", value:src},function(rsp){
                 layer.closeAll();
                    layer.msg(rsp.msg, {
                      offset: 'auto',
                      anim: 6,
                      end:function(){
                       
                      }
                 });
            })
               return layer.msg("上传成功");
          }
          if(res.code = 0){
             return layer.msg('上传失败');
          }else{
              document.getElementById("showImg").src= res.data.url; //图片链接（base64）.src= res.data.url
               var src=res.data.url
               $.post('user/profilesingle',{field:"avatar", value:src},function(rsp){
                 layer.closeAll();
                    layer.msg(rsp.msg, {
                      offset: 'auto',
                      anim: 6,
                      end:function(){
                       
                      }
                 });
            })
             return layer.msg('上传成功');
          }
         
          //上传成功
        }
      });
    });
   
</script>
